package com.woniuxy.repair.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@FeignClient(name = "flowable-server", url = "${feign.flowable-server.url}", path = "/api/baoxiu")
public interface BaoxiuFeign {
    @PostMapping("/start")
    ResponseEntity<Map<String, Object>> startRepairFlow(@RequestBody Map<String, Object> request);

    @PostMapping("/{repairOrderId}/approve")
    ResponseEntity<Void> approveRepairFlow(
            @PathVariable("repairOrderId") Long repairOrderId,
            @RequestBody Map<String, Object> request
    );

    @GetMapping("/process/diagram/{processInstanceId}")
    void getProcessDiagram(@PathVariable("processInstanceId") String processInstanceId, HttpServletResponse response);

    @GetMapping("/process/{processInstanceId}")
    ResponseEntity<Map<String, Object>> getProcessInstance(@PathVariable("processInstanceId") String processInstanceId);

    @PostMapping("/{repairOrderId}/handle")
    ResponseEntity<Void> handleRepairFlow(
            @PathVariable("repairOrderId") Long repairOrderId,
            @RequestParam("feedback") String feedback,
            @RequestHeader("X-User-ID") String userId
    );

    @PostMapping("/{repairOrderId}/confirm")
    ResponseEntity<Void> confirmRepairFlow(
            @PathVariable("repairOrderId") Long repairOrderId,
            @RequestParam("satisfied") Boolean satisfied,
            @RequestParam(value = "evaluation", required = false) String evaluation,
            @RequestParam(value = "rating", required = false) Integer rating,
            @RequestHeader("X-User-ID") String userId
    );

    @PostMapping("/{repairOrderId}/cancel")
    ResponseEntity<Void> cancelRepairFlow(
            @PathVariable("repairOrderId") Long repairOrderId,
            @RequestParam("reason") String reason,
            @RequestHeader("X-User-ID") String userId
    );

    @PostMapping("/{repairOrderId}/handle")
    ResponseEntity<Void> handleRepairFlow(
            @PathVariable("repairOrderId") Long repairOrderId,
            @RequestBody Map<String, Object> request
    );

    @GetMapping("/repair/tasks/{userId}")
    ResponseEntity<Map<String, Object>> getRepairTasks(@PathVariable("userId") String userId);
}
